#!/usr/bin/env python3
"""
CAN总线学习demo启动脚本
同时运行发送器和接收器
"""

import subprocess
import sys
import time
import signal
import os

def main():
    print("🚗 CAN总线学习demo")
    print("=" * 40)
    print("将同时启动发送器和接收器")
    print("发送器：模拟车辆信号")
    print("接收器：接收并校验信号")
    print("=" * 40)
    print()
    
    # 启动接收器（后台运行）
    print("📥 启动接收器...")
    receiver_process = subprocess.Popen([sys.executable, "can_receiver.py"])
    
    # 等待一下让接收器准备就绪
    time.sleep(2)
    
    # 启动发送器（前台运行）
    print("📡 启动发送器...")
    try:
        sender_process = subprocess.run([sys.executable, "can_sender.py"])
    except KeyboardInterrupt:
        print("\n⏹️ 正在停止程序...")
    finally:
        # 停止接收器
        receiver_process.terminate()
        receiver_process.wait()
        print("👋 程序已退出")

if __name__ == "__main__":
    main() 